package extrace.loader;

import java.util.List;

import android.app.Activity;
import android.util.Log;

import com.google.gson.reflect.TypeToken;

import extrace.misc.model.Express;
import extrace.misc.model.TransPackage;
import extrace.misc.model.Transhistory;
import extrace.net.HttpAsyncTask;
import extrace.net.HttpResponseParam;
import extrace.net.HttpResponseParam.RETURN_STATUS;
import extrace.net.IDataAdapter;
import extrace.net.JsonUtils;
import extrace.ui.main.ExTraceApplication;

public class TransPackageListLoader extends HttpAsyncTask{

	String url;
	IDataAdapter<List<TransPackage>> adapter;
	private Activity context;
	
	public TransPackageListLoader(IDataAdapter<List<TransPackage>> adpt, Activity context) {
		super(context);
		this.context = context;
		adapter = adpt;
		url = ((ExTraceApplication)context.getApplication()).getDomainServiceUrl()+"Transpackage/";
	}

	@Override
	public void onDataReceive(HttpResponseParam param) {
		Log.v("getTranspackages",param.getResponseString());
		String state = param.getState();
		if(state.equals("read_success")){
			List<TransPackage> transPackages = JsonUtils.fromJson(param.getResponseString(), new TypeToken<List<TransPackage>>(){});
			adapter.setData(transPackages);
			adapter.notifyDataSetChanged();
		}
	}

	@Override
	public void onStatusNotify(RETURN_STATUS status, String str_response) {
		// TODO Auto-generated method stub
	}
	public void getTranspackagesByCreater(){
		String _url = url + "getTranspackagesByCreater";
		try {
			Log.v("getTranspackages",_url);
			execute(_url, "GET");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
